from django.db import models
# from django.contrib.auth.models import User
from django.template.defaultfilters import slugify

# Create your models here.


class Article(models.Model):
    url = models.URLField()
    title = models.CharField(max_length=50)
    title_slug = models.SlugField(unique=True)
    author = models.CharField(max_length=50)
    content_md = models.TextField()
    content_html = models.TextField()
    tags = models.CharField(max_length=30)
    views = models.IntegerField()
    created = models.DateTimeField()
    updated = models.DateTimeField()

    def save(self, *args, **kwargs):
        self.title_slug = slugify(self.title)
        self.url = r'/article/%s/' % (self.title_slug,)
        super(Article, self).save(*args, **kwargs)

    def __unicode__(self):
        return self.title_slug
